#!/usr/bin/env python
#coding:utf-8

import wx

class CoorPanel ( wx.Panel ):
    
    def __init__( self, parent ):
        wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( -1,-1 ), style = wx.TAB_TRAVERSAL )
        
        bSizer43 = wx.BoxSizer( wx.VERTICAL )
        
        self.m_bitmap8 = wx.StaticBitmap( self, wx.ID_ANY, wx.Bitmap( u"images/sheet2.png", wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer43.Add( self.m_bitmap8, 0, wx.RIGHT|wx.LEFT, 50 )
        
        self.SetSizer( bSizer43 )
        self.Layout()
        bSizer43.Fit( self )
        
        self.LY1E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.left_y1, pos = wx.Point(238, 137), size = (50, -1), style = wx.TE_CENTER)
        self.LX2E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.left_x2, pos = wx.Point(96, 156), size = (50, -1), style = wx.TE_CENTER)
        self.LX3E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.left_x3, pos = wx.Point(176, 156), size = (50, -1), style = wx.TE_CENTER)
        self.LY3E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.left_y3, pos = wx.Point(238, 247), size = (50, -1), style = wx.TE_CENTER)
        
        self.RY4E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.right_y4, pos = wx.Point(238 + 370, 137), size = (50, -1), style = wx.TE_CENTER)
        self.RX5E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.right_x5, pos = wx.Point(76 + 370, 156), size = (50, -1), style = wx.TE_CENTER)
        self.RX6E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.right_x6, pos = wx.Point(176 + 370, 156), size = (50, -1), style = wx.TE_CENTER)
        self.RY6E = wx.TextCtrl(self.m_bitmap8, value = u'%.3f' % app.pref.right_y6, pos = wx.Point(238 + 370, 247), size = (50, -1), style = wx.TE_CENTER)
        
    def GetData(self):
        y1 = float(self.LY1E.GetValue())
        x2 = float(self.LX2E.GetValue())
        x3 = float(self.LX3E.GetValue())
        y3 = float(self.LY3E.GetValue())
        y4 = float(self.RY4E.GetValue())
        x5 = float(self.RX5E.GetValue())
        x6 = float(self.RX6E.GetValue())
        y6 = float(self.RY6E.GetValue())
        return y1,x2,x3,y3,y4,x5,x6,y6

class CoordinateDialog ( wx.Dialog ):
    
    def __init__( self, parent ):
        wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"坐标系设置", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
        
        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        
        bSizer39 = wx.BoxSizer( wx.VERTICAL )
        
        bSizer2 = wx.BoxSizer( wx.HORIZONTAL )
        
        self.m_bitmap1 = wx.StaticBitmap( self, wx.ID_ANY, wx.Bitmap( u"images/leaf.png", wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer2.Add( self.m_bitmap1, 0, wx.ALL, 5 )
        
        self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, u"在这里设置测量坐标系", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText1.Wrap( -1 )
        self.m_staticText1.SetFont( wx.Font( 15, 70, 90, 92, False, wx.EmptyString ) )
        self.m_staticText1.SetForegroundColour( wx.Colour( 32, 141, 20 ) )
        
        bSizer2.Add( self.m_staticText1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        bSizer39.Add( bSizer2, 0, wx.EXPAND, 5 )
        
        self.m_staticline1 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
        bSizer39.Add( self.m_staticline1, 0, wx.EXPAND |wx.ALL, 5 )
        
        self.m_bitmap8 = CoorPanel(self)
        bSizer39.Add( self.m_bitmap8, 0, wx.RIGHT|wx.LEFT, 50 )
        
        self.m_staticline17 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
        bSizer39.Add( self.m_staticline17, 0, wx.EXPAND |wx.ALL, 5 )
        
        m_sdbSizer1 = wx.StdDialogButtonSizer()
        self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK, label = u'确定' )
        m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
        self.m_sdbSizer1Cancel = wx.Button( self, wx.ID_CANCEL, label = u'取消' )
        m_sdbSizer1.AddButton( self.m_sdbSizer1Cancel )
        m_sdbSizer1.Realize();
        bSizer39.Add( m_sdbSizer1, 1, wx.EXPAND, 5 )
        
        self.SetSizer( bSizer39 )
        self.Layout()
        bSizer39.Fit( self )
        
        self.Centre( wx.BOTH )
        
        self.m_sdbSizer1OK.Bind(wx.EVT_BUTTON, self.OnOK)
        
    def OnOK(self, evt):
        try:
            y1,x2,x3,y3,y4,x5,x6,y6 = self.m_bitmap8.GetData()
            app.pref.left_y1 = y1
            app.pref.left_x2 = x2
            app.pref.left_x3 = x3
            app.pref.left_y3 = y3
            app.pref.right_y4 = y4
            app.pref.right_x5 = x5
            app.pref.right_x6 = x6
            app.pref.right_y6 = y6
            app.pref.save()
        except:
            wx.MessageBox(u'输入的数据存在错误')
            return
        evt.Skip()
        